﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utilities
{
    public class JsonMessager
    {
        /// <summary>
        /// 未登录或登录超时
        /// </summary>
        public static string NeedLogin
        {
            get { return "{\"result\":{\"r\":\"needLogin\",\"val\":\"您还未登录，或登录已失效，请登录！\"}}"; }
        }

        /// <summary>
        /// 参数错误
        /// </summary>
        public static string ParamError
        {
            get { return "{\"result\":{\"r\":\"error\",\"val\":\"参数错误！\"}}"; }
        }

        /// <summary>
        /// 运行错误
        /// </summary>
        public static string RunError
        {
            get { return "{\"result\":{\"r\":\"error\",\"val\":\"运行错误！\"}}"; }
        }

        /// <summary>
        /// 成功提示
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string Success(object val)
        {
            string str = val.ToString();
            if (!str.StartsWith("[") || !str.EndsWith("]"))
            {
                str = "\"" + str + "\"";
            }
            return string.Format("{{\"result\":{{\"r\":\"suc\",\"val\":{0}}}}}", str);
        }

        /// <summary>
        /// 失败提示
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string Fail(object val)
        {
            return string.Format("{{\"result\":{{\"r\":\"fail\",\"val\":\"{0}\"}}}}", val);
        }
    }
}
